package com.happe.foodeasy.dao;

import com.happe.foodeasy.system.entity.LinkedImage;
import org.springframework.jdbc.core.PreparedStatementSetter;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.jdbc.support.rowset.SqlRowSet;

import java.util.List;
import java.util.Map;

/**
 * Extract fundamental method of visiting database.
 * Created by wubin on 2016-05-02.
 */
public interface CommonDao<T> {
    /**
     * save one target object's data to database.
     *
     * @param saveTarget the target object that should be saved.
     */
    void save(T saveTarget);

    /**
     * update one target object's data in database by target object's id.
     *
     * @param updateTarget the target object that should be updated.
     */
    void update(T updateTarget);

    /**
     * delete one target object's data in database by target object's id.
     *
     * @param deleteTarget the target object that should be deleted.
     */
    void delete(T deleteTarget);

    /**
     * in sql, have ? placeholder. use the second parameter to replace placeholder,
     * and use the third to get the result.
     *
     * @param sql     sql for retrieve database, in the sql, has placeholder(?).
     * @param setter  replace the placeholder in sql.
     * @param handler retrieve the result.
     */
    void selectBySql(String sql, PreparedStatementSetter setter, RowCallbackHandler handler);

    /**
     * retrieve data by one property.
     *
     * @param params should appear in couple.
     * @return the set of result.
     */
    List<T> findManyByProperty(Object... params);

    /**
     * This method is used to retrieve one target entity.
     *
     * @param params The params must be couple, columnName and value
     * @return The result of retrieving.
     */
    T findOneByProperties(Object... params);

    /**
     * This method is used to retrieve special sequence's value.
     *
     * @param sequenceName the name of sequence.
     * @return the special sequence's next value.
     */
    long getSequenceNextValue(String sequenceName);
}
